#include "database.h"

Database::Database(std::string const &file_name)
:m_file_name(file_name)
,m_db(0)
{
}

Database::~Database()
{
    if(m_db)
    {
        sqlite3_close(m_db);
    }
}

int Database::open()
{
    int rc = 0;
    rc = sqlite3_open(m_file_name.c_str(), &m_db);
    if(rc){
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(m_db));
        sqlite3_close(m_db);
        return 1;
    }
    return 0;
}

int Database::initialize()
{
    
}


??? Database::exec_query(std::string const &query)
{
    if(!m_db)
        return 1;
    
    int status = 0;
    sqlite3_stmt *stmt;
    
    status = sqlite3_prepare(m_db, query.c_str(), -1, &stmt, 0);
    if(status != SQLITE_OK)
    {
        return 1;
    }
    
    int cols = sqlite3_column_count(stmt);
    int result = 0;

    while(sqlite3_step(stmt) == SQLITE_ROW)
    {
        for(int col = 0; col < cols; col++)
        {
            
        }
    }
    
    sqlite3_finalize(statement);
}